package cloud.dandanit.itservice.controller.index;


import cloud.dandanit.itservice.config.limitCurrentConfig.RateLimit;
import cloud.dandanit.itservice.entity.Banner;
import cloud.dandanit.itservice.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.support.atomic.RedisAtomicInteger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api("首页限流")
//@CrossOrigin
@RestController
@RequestMapping("/itservice/frontindex")
public class LimitCurrent {

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation(value = "限流")
    @GetMapping("limitCurrent")
    @RateLimit(key = "limitCurrent", time = 10, count = 10)
    public R limitCurrent() {

        RedisAtomicInteger entityIdCounter = new RedisAtomicInteger("entityIdCounter", redisTemplate.getConnectionFactory());
        return R.ok().data("viewCount",entityIdCounter.getAndIncrement());
    }
}
